CDT = {
  pageSize:20,
  taskTemp:null
};

function loadPage(pageNo) {
	var preUrl=window.location.href.indexOf("/admin")>0?"/admin":"/seller";
	var sellerNick=$("#sellerNick").val();
	var shop=$("#shop").val();
	var beginTakeTime=($.trim($("#beginTakeTime").val())) ? $.trim($("#beginTakeTime").val()) + ' 00:00:00' : '';
	var endTakeTime=($.trim($("#endTakeTime").val())) ? $.trim($("#endTakeTime").val()) + ' 00:00:00' : '';

	Tr.get(preUrl+'/task/blanceWdList', {
		'vo.pageNo' : pageNo,
		'vo.pageSize' : CDT.pageSize,
		'vo.beginTakeTime':beginTakeTime,
		'vo.endTakeTime':endTakeTime,
		'vo.sellerNick':sellerNick
	}, function(data) {
		if (data.code != 200)
			return;
		if (data.results.length <= 0) {
			$('.normTable').hide();
			$('#noMsg').show();
			$('.pagin-btm').hide();
			return;
		}
		var url=preUrl+"/task/exportSellerWdBlance?vo.beginTakeTime="+beginTakeTime+"&vo.endTakeTime="+endTakeTime+"&vo.sellerNick="+sellerNick;
		$("#expoptBtn").attr("href",url);

        var output = Mustache.render(CDT.taskTemp, $.extend(data, {
            takenTime : function() {
                return new Date(this.takeTime).Format('yyyy-MM-dd hh:mm:ss');
            },baseCommissionStr:function(){
                return this.baseCommission/100;
            },cashbackStr:function(){
                return this.cashback/100;
            }
        }));
        $('#blanceContainer').html(output);
        $('#noMsg').hide();
		
		$('.pagin-btm').show();
		$('.pagination').pagination(data.totalCount, {
			items_per_page : CDT.pageSize,
			num_display_entries : 5,
			current_page : pageNo,
			num_edge_entries : 2,
			callback : loadOrderCallBack,
			callback_run : false
		});
		CDT.currPageNo = pageNo;
	});
}
function loadOrderCallBack(index, jq) {
	loadPage(index + 1);
}
function initBaseBind() {
	$('.inputDate').datePicker({
		startDate: '2014-01-01',
		endDate: '2020-01-01',
		clickInput: true,
		verticalOffset: 35
	});

	$("#queryBtn").click(function(){
		loadPage(1);
	});
	$("#nuExpoptBtn").click(function(){
		alert("当前导出数量过多！请按条件查询后再导出");
	});
	
}
$(function() {
	CDT.taskTemp = $('#taskTemp').remove().val();
	Mustache.parse(CDT.taskTemp);
	loadPage(1);
	initBaseBind();
});